import 'package:flutter/material.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/pages/user_info/model/UserModel.dart';
import 'package:huajianshe_app/utils/dialog_util.dart';
import 'package:huajianshe_app/widget/AvatarWidget.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

import 'LeaveMessageDialog.dart';

class UserMomentHeader extends StatelessWidget {

  final UserInfo? userInfo;
  final int? total;
  final int? circleId;

  const UserMomentHeader({Key? key, this.userInfo, this.total = 0, this.circleId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(mainAxisSize: MainAxisSize.min,
      children: [
        H(124),
        SizedBox(width: double.infinity, child: Stack(children: [
          Padding(padding: EdgeInsets.only(top: 24), child:
          Row(mainAxisSize: MainAxisSize.max, children: <Widget>[
            Expanded(child:
              RoundedCornerWidget(width: double.infinity, backgroundColor: C.grayF6, borderColor: Colors.transparent,
                radius: 13, cornerPosition: 3, child:
                Column(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start,
                    children: [...buildUserInfo(context)]),
              )
            )
          ]),
          ),
          //头像
          Positioned(left: 16, child:
            AvatarWidget(userInfo?.avatar, 66, 3, 1))
        ])),
      ],
    );
  }

  List<Widget> buildUserInfo(BuildContext context) {
    return [
      H(9),
      Row(mainAxisSize: MainAxisSize.max, children: [
        Spacer(),
        SmartButton(text: userInfo?.isFriend == 1 ? '聊天' : '留言', height: 32, width: 72,
          onPressed: () { chatOrMessage(context); }, radius: 16, drawableLeft: LoadImage('ic_message'), drawablePadding: 3,),
        W(15)
      ]),
      H(10),
      Row(mainAxisSize: MainAxisSize.min, children: [
        W(15),
        Text('${userInfo?.nickname}', style: TS(18, C.gray333)),
        W(3.5),
        if ((userInfo?.sex ?? 0 )> 0) LoadImage('${userInfo?.sex == 2 ? 'ic_female' : 'ic_male'}'),
      ]),
      H(3),
      Row(mainAxisSize: MainAxisSize.min, children: [
        W(15),
        Text('${userInfo?.companyName}${userInfo?.positionName}', style: TS(13, C.gray666),),

      ]),
      H(12),
      RoundedCornerWidget(radius: 13, cornerPosition: 3, backgroundColor: Colors.white, borderWidth: 0, borderColor: Colors.transparent, width: double.infinity, height: 44,
          boxShadowList: [
            BoxShadow(color: Color.fromRGBO(0x35, 0x49, 0x5D, 0.2), blurRadius: 15),
            BoxShadow(color: Colors.white, offset: Offset(0, 16)),
          ],
          child: Row(mainAxisSize: MainAxisSize.min, children: [
            W(14),
            IntrinsicWidth(
                child: Column(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      H(10),
                      Text('全部动态 ${total}', style: TS(15, C.gray0D0E15)),
                      Spacer(),
                      Center(child: Container(color: Colors.red, width: 34, height: 2.5,))
                    ]
                )
            )
          ])
      ),
      D()
    ];
  }

  void chatOrMessage(BuildContext context) {
    if (userInfo?.isFriend == 1) { // 好友去聊天

    } else { // 非好友去留言
      DialogUtil.showBottomDialogV2(context, LeaveMessageDialog(circleId), height: 0.8, radius: 13,
          bgColor: Colors.transparent, margin: EdgeInsets.symmetric(horizontal: 5));
    }
  }
}